package users;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import util.Entity;
import builders.UserAccountBuilder;

/**
 * Depicts an user account
 */
public class UserAccount extends Entity {

    // ---------INSTANCE VARIABLES-----------------------------------------//

    private static final long serialVersionUID = 1L;

    private String userID;

    private String password;

    private Role role;

    // ---------CONSTRUCTORS------------------------------------------------//

    public UserAccount(final String anUserID) {
        super();
        userID = anUserID;
    }

    public UserAccount(final UserAccountBuilder builder) {
        super();
        userID = builder.getUserID();
        role = builder.getRole();
        password = builder.getPassword();
    }

    public UserAccount() {
        super();
        // emtpy constructor
    }

    public UserAccount(final String anUserID, final String aPassword, final Role aRole) {
        super();
        userID = anUserID;
        password = aPassword;
        role = aRole;
    }

    // ---------ACCESSORS---------------------------------------------------//

    public String getUserID() {
        return userID;
    }

    public void setUserID(final String userID) {
        this.userID = userID;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(final String password) {
        this.password = password;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(final Role role) {
        this.role = role;
    }

    // ---------OTHER BEHAVIOUR---------------------------------------------//

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 31).append(getUserID()).toHashCode();
    }

    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != this.getClass()) {
            return false;
        }

        UserAccount rhs = (UserAccount) obj;
        return new EqualsBuilder().append(getUserID(), rhs.getUserID()).isEquals();
    }

}
